<template>
  <div>
    <IPCCfg ref="ipcDlg" @add_finished="refresh"></IPCCfg>
    <a-space>
      <a-button @click="refresh">刷新</a-button>
      <a-button @click="edit">编辑</a-button>
    </a-space>
    <vxe-table ref="cameraTable" :data="ipcs" size="small">
      <vxe-table-column field="s_name" title="名称" sortable>
      </vxe-table-column>
      <vxe-table-column field="ip" title="IP"> </vxe-table-column>
      <vxe-table-column field="rtsp" title="视频rtsp地址"> </vxe-table-column>
      <vxe-table-column field="business_id" title="sn"></vxe-table-column>
      <vxe-table-column field="b" title="板编号"> </vxe-table-column>
      <vxe-table-column field="p" title="接口"> </vxe-table-column>
      <vxe-table-column
        field="state"
        title="在线状态"
        :formatter="formatterState"
        :filters="stateList"
      >
      </vxe-table-column>
      <vxe-table-column title="操作" width="160">
        <template #default="{ row }">
          <template v-if="row.rtsp && row.rtsp.length > 0">
            <a-icon type="play-square" @click="playVideo(row)" />
          </template>
        </template>
      </vxe-table-column>
    </vxe-table>
  </div>
</template>
<script>
import IPCCfg from "../../cfg/dcfg/IPCCfg.vue";
import {playVideo } from "@/services/ipc";
const stateList = [
  { label: "离线", value: 0 },
  { label: "在线", value: 1 },
];
export default {
  components: { IPCCfg },
  props: ["ipcs"],
  data() {
    return {
      stateList,
    };
  },
  methods: {
    formatterState(item) {
      let cellValue = item.cellValue;
      if (cellValue == undefined) {
        return "未知";
      }
      if (cellValue == "-") {
        return cellValue;
      }
      console.log("____________", cellValue);
      return stateList[cellValue].label;
    },
    refresh() {
      this.$emit("getipcs");
    },
    edit() {
      this.$refs.ipcDlg.showDlg({
        uid: this.$store.state.thingView.activeThing.tid,
        station_id:this.$store.state.thingView.activeThing.info.station_id,
      });
    },
     playVideo(row) {
      playVideo(this,row.rtsp)
    },
  },
};
</script>